package com.jkc.xh.adapters.viewholder;

import android.content.Context;
import android.util.AttributeSet;
import android.view.View;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.jkc.xh.R;
import com.jkc.xh.models.HoldAllModel;

import org.androidannotations.annotations.EViewGroup;
import org.androidannotations.annotations.ViewById;

/**
 * Created by wangjie28 on 2015/11/13.
 */
@EViewGroup(R.layout.item_factory_hold_all)
public class MyFactoryHoldAllItemView extends RelativeLayout {

    @ViewById(R.id.optionLayout)
    View optionLayout;
    @ViewById(R.id.dataLayout)
    View dataLayout;
    @ViewById(R.id.stock_name)
    TextView stock_name;
    @ViewById(R.id.stock_code)
    TextView stock_code;
    @ViewById(R.id.own_amount)
    TextView own_amount;
    @ViewById(R.id.enable_amount)
    TextView enable_amount;
    @ViewById(R.id.freeze_sell_amount)
    TextView freeze_sell_amount;
    @ViewById(R.id.cost_price)
    TextView cost_price;
    @ViewById(R.id.last_price)
    TextView last_price;
    @ViewById(R.id.market_value)
    TextView market_value;
    @ViewById(R.id.profit_money)
    TextView profit_money;
    @ViewById(R.id.profit_rate)
    TextView profit_rate;
    @ViewById(R.id.add_dpt_money)
    TextView add_dpt_money;
    @ViewById(R.id.add_fee_money)
    TextView add_fee_money;

    public MyFactoryHoldAllItemView(Context context) {
        super(context);
    }

    public MyFactoryHoldAllItemView(Context context, AttributeSet attrs) {
        super(context, attrs);
    }


    public void bind(HoldAllModel model) {
        stock_name.setText(model.stock_name);
        stock_code.setText(model.stock_code);
        own_amount.setText(model.own_amount);
        enable_amount.setText(model.enable_amount);
        freeze_sell_amount.setText(model.freeze_sell_amount);
        cost_price.setText(model.cost_price);
        last_price.setText(model.last_price);
        market_value.setText(model.market_value);
        profit_money.setText(model.profit_money);
        profit_rate.setText(model.profit_rate);
//        add_dpt_money.setText(model.add_dpt_money);
//        add_fee_money.setText(model.add_fee_money);

        if (model.isProfit()) {
            setAllTextColor(getResources().getColor(R.color.text_color_red));
        } else {
            setAllTextColor(getResources().getColor(R.color.text_color_blue));
        }
        if (model.isStop()) {
            last_price.setText("一一");
            setAllTextColor(getResources().getColor(R.color.text_color_gray));
        }
    }

    public void showMoreOption() {
        optionLayout.setVisibility(View.VISIBLE);
    }

    public void disableMoreOption() {
        optionLayout.setVisibility(View.GONE);
//        dataLayout.setBackgroundColor(R.color);
    }

    private void setAllTextColor(int textColorId) {
        stock_name.setTextColor(textColorId);
        stock_code.setTextColor(textColorId);
        own_amount.setTextColor(textColorId);
        enable_amount.setTextColor(textColorId);
        freeze_sell_amount.setTextColor(textColorId);
        cost_price.setTextColor(textColorId);
        last_price.setTextColor(textColorId);
        market_value.setTextColor(textColorId);
        profit_money.setTextColor(textColorId);
        profit_rate.setTextColor(textColorId);
    }

}
